<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <input type="text" v-model="mass" @keyup.enter.ctrl="goup">
        a{{a}}*b{{b}}={{gai}}
        <button @click="gai()">11</button>
        <button @click="setnum()">点我修改b的值</button>

        <p><input type="text" v-model="a">a</p>
        <p><input type="text" v-model="b">b</p>
        <p><input type="text" v-model="total">a*b</p>
    </div>
</body>
<script src="../../vue.js"></script>
<script>
    new Vue({
        el:"#app",
        data:{
            mass:""
            ,a:10,
            b:20
            ,total:200
            ,obj:{
                name:20,
                ab:{
                    age:20
                }
            }
        },
        methods:{
            goup(){
                // console.log(this.mass);
            },
            setnum(){
                // this.a=5
                // this.obj={
                //     name:30
                // }
                this.obj={
                    name:20,
                    ab:{
                    age:30
                    }
                }
            },
            
        },
        computed:{
            gai:{
                get(){
                   return this.a*this.b
                    console.log("改变了");
                },
                set(newvalue){
                    this.a=newvalue;
                }
            }
        },
        watch:{
            a:function(newvalue){
                setTimeout(()=>{
                    this.total = newvalue*this.b
                },1000)
            },
            b:function(newvalue){
                setTimeout(()=>{
                    this.total = newvalue*this.a
                },1000)
            },
            // "obj.name":function(newvalue,oldvalue){
            //     console.log(newvalue,oldvalue);
            // },
            obj:{
                handler(newvalue,oldvalue){
                    console.log(newvalue,oldvalue);
                },
                deep:true
            },
        }
    })
</script>
</html>